package com.tencent.qcloud.tuikit.tuichat.bean.message;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.tencent.imsdk.v2.V2TIMMessage;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean;
import com.tencent.qcloud.tuikit.timcommon.bean.TUIReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.R;
import com.tencent.qcloud.tuikit.tuichat.TUIChatService;
import com.tencent.qcloud.tuikit.tuichat.bean.CustomBusinessCardMessage;
import com.tencent.qcloud.tuikit.tuichat.bean.message.reply.CustomBusinessCardMessageReplyQuoteBean;
import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;

public class CustomBusinessCardMessageBean extends TUIMessageBean {

    private CustomBusinessCardMessage orderMessage;

    @Override
    public String onGetDisplayString() {
        return getExtra();
    }

    @Override
    public void onProcessMessage(V2TIMMessage v2TIMMessage) {
        String data = new String(v2TIMMessage.getCustomElem().getData());
        TUIChatLog.d("CustomOrderMessageBean", "data = " + data);
        if (!TextUtils.isEmpty(data)) {
            try {
                orderMessage = new Gson().fromJson(data, CustomBusinessCardMessage.class);
            } catch (Exception e) {
                TUIChatLog.e("CustomOrderMessageBean", "exception e = " + e);
            }
        }
        if (orderMessage != null) {
            setExtra(TUIChatService.getAppContext().getString(R.string.bus_card));
        } else {
            String text = TUIChatService.getAppContext().getString(R.string.no_support_msg);
            setExtra(text);
        }
    }

    public String getUserID() {
        if (orderMessage != null) {
            return orderMessage.userID;
        }
        return "";
    }

    public String getUserName() {
        if (orderMessage != null) {
            return orderMessage.userName;
        }
        return "";
    }

    public String getUserHead() {
        if (orderMessage != null) {
            return orderMessage.userHead;
        }
        return "";
    }

    @Override
    public Class<? extends TUIReplyQuoteBean> getReplyQuoteBeanClass() {
        return CustomBusinessCardMessageReplyQuoteBean.class;
    }
}
